import { Singleton } from "../core/Singleton";
//class MenuManager
    
    export  class MenuManager extends Singleton
    {
        constructor()
        {
            
            super();this._contextMenu = new Object /* flash.ui.ContextMenu */();
            this._contextMenu.hideBuiltInItems();
            return;
        }

        public initMenu(arg1: Object /* flash.display.DisplayObjectContainer */): void
        {
            this._container = arg1;
            if (this._container) 
            {
                this._container.contextMenu = this._contextMenu;
            }
            return;
        }

        public addItem(arg1: string, arg2: Function=null): void
        {
            var menuLabel: string;
            var callback: Function=null;
            var isCallback: Boolean;
            var item: Object /* flash.ui.ContextMenuItem */;
            var menuItemSelectHandler: Function;

            var loc1;
            item = null;
            menuLabel = arg1;
            callback = arg2;
            isCallback = callback is Function;
            if (isCallback) 
            {
                item = new Object /* flash.ui.ContextMenuItem */(menuLabel, false);
            }
            else 
            {
                item = new Object /* flash.ui.ContextMenuItem */(menuLabel, false, false);
            }
            this._contextMenu.customItems.push(item);
            if (isCallback) 
            {
                menuItemSelectHandler = (arg1: Object /* flash.events.ContextMenuEvent */): void
                {
                    callback();
                    return;
                }
                item.addEventListener(flash.events.ContextMenuEvent.MENU_ITEM_SELECT, menuItemSelectHandler);
            }
            return;
        }

        public static get instance(): MenuManager
        {
            if (MenuManager._instacne == null) 
            {
                MenuManager._instacne = new MenuManager();
            }
            return MenuManager._instacne;
        }

        private /* var */_contextMenu: Object /* flash.ui.ContextMenu */;

        private /* var */_container: Object /* flash.display.DisplayObjectContainer */;

        private static /* var */_instacne: MenuManager;
    }
